<include file="public/layout"/>
<style>
    .te_le .dataTables_paginate{float: left;}
    .bot{float: right;padding: 15px 0}
</style>
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div class="page" style="padding: 0px 1% 0 1%;">
	
    <!-- 操作说明 -->
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>礼券</h3>
                <h5>(共{$page->totalRows}条记录)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline" id="search-form2" action="{:U('coupon/search_coupon')}" method="get">

                <div class="sDiv">                    
                    <div class="sDiv2">                       
                        <input size="30" name="key_word" value="{$Request.param.key_word}" class="qsbox" placeholder="商品名称或者关键词" type="text">
                        <input type="hidden" name="exvirtual" value="{$Request.param.exvirtual}"/>
                        <input class="btn" value="搜索" type="submit">
                    </div>
                </div>
            </form>
        </div>
        
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th abbr="article_title" axis="col3" class="" align="left">
                            <div style="text-align: left; width: 50px;" class=""><input type="checkbox" class="checkAll"></div>
                        </th>
                        <th abbr="ac_id" axis="col4" class="" align="left">
                            <div style="text-align: center; width: 80px;" class="">ID</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="" align="left">
                            <div style="text-align: left; width: 200px;" class="">礼券名称</div>
                        </th>
                        <th abbr="ac_id" axis="col4" class="" align="left">
                            <div style="text-align: center; width: 150px;" class="">获得后多少天可使用</div>
                        </th>
                        <th abbr="article_show" axis="col5" class="" align="center">
                            <div style="text-align: center; width: 150px;" class="">有效时长(天)</div>
                        </th>
                        <th style="width:100%" axis="col7">
                            <div></div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table>
                    <tbody id="goos_table">
                    <volist name="clist" id="list">
                        <tr >
                            <td class="" align="left">
                                <div style="text-align: left; width: 50px;">
                                    <input class="checkItem" type="checkbox" name="coupon_id[]" value="{$list.id}" data-img="{$list.iconurl}"
                                           data-name="{$list.cname}" data-stm="{$list.starttime/(24*60*60)}" data-id="{$list.id}"
                                           data-etm="{$list.endtime/(24*60*60)}" data-check="{$list.ischeck}"/>
                                </div>
                            </td>
                            <td class="" align="left">
                                <div style="text-align: center; width: 80px;">{$list.id}</div>
                            </td>
                            <td class="" align="left">
                                <div style="text-align: left; width: 200px;">{$list.cname}</div>
                            </td>
                            <td class="" align="left">
                                <div style="text-align: center; width: 150px;">{$list.starttime/(24*60*60)}</div>
                            </td>
                            <td class="" align="left">
                                <div style="text-align: center; width: 150px;">{$list.endtime/(24*60*60)}</div>
                            </td>
                            <td class="" style="width: 100%;" align="">
                                <div>&nbsp;</div>
                            </td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <!--分页位置-->
        <div class="te_le">
            {$page}
        </div>
        <div class="bot"><a onclick="select_coupon();" class="ncap-btn-big ncap-btn-green">确认提交</a></div>
    </div>
</div>
<script>
	
	var haveArr = [];
    $(document).ready(function(){
        $("input[type='checkbox']").each(function(i,o){
			var cname = $(o).data('name');
			var check = $(o).data('check');
			if(check==1){
				$(o).attr('checked','checked');
			}

			haveArr.push('check='+check);
			console.log('cname='+cname+"check="+check);
        })
    });
    
    //规格按钮点击事件
    $(function () {
        $(document).on("click", '.specBtn', function (e) {
            if($(this).hasClass('ncap-btn-green')){
                $(this).css("color","#777").removeClass('ncap-btn-green');
            }else{
                $(this).css("color","#FFF").addClass('ncap-btn-green');
            }
        })
    })
    //全选选中事件
    $(function () {
        $(document).on("click", '.checkAll', function (e) {
            if($(this).is(':checked')){
                $('.checkItem').each(function(i,o){
                    $(o).attr('checked','checked');
                })
                $("input[type='checkbox']:checked").each(function(i,o){
                    var goods_id = $(this).val();
                })
                $('.specBtn').css("color","#FFF").addClass('ncap-btn-green');
            }else{
                $('.checkItem').each(function(i,o){
                    $(o).removeAttr('checked');
                })
                $("input[type='checkbox']").each(function(i,o){
                    var goods_id = $(this).val();
                })
                $('.specBtn').css("color","#777").removeClass('ncap-btn-green');
            }
        })
    })
    //复选框选中事件
    $(function () {
        $(document).on("click", '.checkItem', function (e) {
        	
            
        })
    })

	function couponItem(c_id,cname,starttime,endtime,c_image){
		this.id = c_id;
        this.cname = cname;
        this.starttime = starttime;
        this.endtime = endtime;
        this.iconurl = c_image;
	}
	
    function select_coupon()
    {
        var inputs = $("input[class='checkItem']:checked");
        if (inputs.length == 0) {
            layer.alert('请选择商品', {icon: 2}); //alert('请选择商品');
            return false;
        }
        
        
        
        var couponArr = new Array();
        inputs.each(function(i,o){
            var cid = $(o).val();
//          if(haveArr.indexOf(cid)<0){
	        	var citem = new couponItem(cid, $(o).data('name'),$(o).data('stm'), $(o).data('etm'),$(o).data('img'));
            	couponArr.push(citem); 
//	        }
            
        })
        if(couponArr.length == 0){
            layer.alert('请至少选择一张礼券');
            return false;
        }
        window.parent.call_coupon_back(couponArr);
    }
</script>
</body>
</html>